<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>资源管理</title>
<link href="${ctx}/static/css/style.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/static/css/select.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}/static/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/static/js/jquery.idTabs.min.js"></script>
<script type="text/javascript" src="${ctx}/static/js/select-ui.min.js"></script>
<link href="${ctx}/static/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/static/css/list.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}/static/js/jquery.ztree.all-3.5.min.js"></script>

<script type="text/javascript">
	KE.show({
		id : 'content7',
		cssPath : './index.css'
	});
</script>

<script type="text/javascript">
	$(document).ready(function(e) {
		$(".select1").uedSelect({
			width : 345
		});
		$(".select2").uedSelect({
			width : 167
		});
		$(".select3").uedSelect({
			width : 100
		});
	});
</script>
</head>
<body>

	<div class="place">
		<span>位置：</span>
		<ul class="placeul">
			<li><a href="#">系统管理</a></li>
			<li><a href="#">权限管理</a></li>
		</ul>
	</div>
	<div class="formbody">
		<ul class="seachform">
			<li class="click add_css"><span><img src="${ctx}/static/images/t01.png"></span>新增</li>
		</ul>
	</div>
	<div class="layer">
	    <div id="tableMain">
	        <ul id="dataTree" class="ztree">
	
	        </ul>
	    </div>
	</div>

<script type="text/javascript">
	//打开新增页面
	$(".add_css").click( function () { 
		window.location.href = '${ctx}/resource/add';
	});
   var zTreeNodes;
    var setting = {
        view: {
            showLine: false,
            showIcon: false,
            addDiyDom: addDiyDom
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    /**
     * 自定义DOM节点
     */
     function addDiyDom(treeId, treeNode) {
        var spaceWidth = 15;
        var liObj = $("#" + treeNode.tId);
        var aObj = $("#" + treeNode.tId + "_a");
        var switchObj = $("#" + treeNode.tId + "_switch");
        var icoObj = $("#" + treeNode.tId + "_ico");
        var spanObj = $("#" + treeNode.tId + "_span");
        aObj.attr('title', '');
        aObj.append('<div class="diy swich"></div>');
        var div = $(liObj).find('div').eq(0);
        switchObj.remove();
        spanObj.remove();
        icoObj.remove();
        div.append(switchObj);
        div.append(spanObj);
        var spaceStr = "<span style='height:1px;display: inline-block;width:" + (spaceWidth * treeNode.level) + "px'></span>";
        switchObj.before(spaceStr);
        var editStr = '';
        editStr += '<div class="diy diy3">' + (treeNode.linkUrl == null ? '&nbsp;' : treeNode.linkUrl) + '</div>';
        editStr += '<div class="diy diy4">' + (treeNode.sort == null ? '&nbsp;' : treeNode.sort) + '</div>';
        editStr += '<div class="diy diy5">' + (treeNode.type == '-' ? '&nbsp;' : treeNode.type ) + '</div>';
        editStr += '<div class="diy diy6">' + formatHandle(treeNode) + '</div>';
        aObj.append(editStr);
    } 
    /**
     * 查询数据
     */
    function query() {
        var data = ${sysResourceTreeList};
        //初始化列表
        zTreeNodes = data;
        //初始化树
        $.fn.zTree.init($("#dataTree"), setting, zTreeNodes);
        //添加表头
        var li_head = ' <li class="head" id="head"><a><div class="diy diy2">权限名称</div><div class="diy diy3">路径</div>' +
            '<div class="diy diy4">排序</div><div class="diy diy5">权限类型</div><div class="diy diy6">操作</div></a></li>';
        var rows = $("#dataTree").find('li');
        rows.find('a').addClass('odd');
        $('.icon_edit').removeClass('odd');
        $('.icon_del').removeClass('odd');
        $('.odd:odd').css("background","#f5f8fa");
        if (rows.length > 0) {
            rows.eq(0).before(li_head);
        } else {
            $("#dataTree").append(li_head);
            $("#dataTree").append('<li ><div style="text-align: center;line-height: 30px;" >无符合条件数据</div></li>')
        }
    }
    /**
     * 根据权限展示功能按钮
     * @param treeNode
     * @returns {string}
     */
    function formatHandle(treeNode) {
        var htmlStr = '';
        htmlStr += '<div class="icon_div"><a class="icon_edit" href="javascript:edit(\'' + treeNode.id + '\')">修改</a></div>';
        htmlStr += '<div class="icon_div"><a class="icon_del" href="javascript:del(\'' + treeNode.id + '\')">删除</a></div>';
        return htmlStr;
    }

    $(function () {
        query(); //初始化数据
    })
    
    function edit(id){
    	window.location.href =  '${ctx}/resource/edit?id='+id;
    }
    
    function del(id){
    	window.location.href =  '${ctx}/resource/delete?id='+id;
    }
    
</script>

</body>
</html>
